import Vue from 'vue'
import Router from 'vue-router'
/* Layout */
import Layout from '../views/layout/Layout'

const _import = require('./_import_' + process.env.NODE_ENV)
// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/** note: submenu only apppear when children.length>=1
 *   detail see  https://panjiachen.github.io/vue-element-admin-site/#/router-and-nav?id=sidebar
 **/

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    roles: ['admin','editor']     will control the page roles (you can set multiple roles)
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
    noCache: true                if true ,the page will no be cached(default is false)
  }
**/
export const constantRouterMap = [
  {
    path: '/login',
    component: _import('login/index'),
    hidden: true
  },
  {
    path: '/authredirect',
    component: _import('login/authredirect'),
    hidden: true
  },
  {
    path: '/404',
    component: _import('errorPage/404'),
    hidden: true
  },
  {
    path: '/401',
    component: _import('errorPage/401'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    children: [
      {
        path: 'dashboard',
        component: _import('dashboard/index'),
        name: 'dashboard',
        meta: {
          title: '首页',
          icon: 'dashboard',
          noCache: true
        }
      }
    ]
  }
]

export default new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  {
    // transactionRecords
    path: '/transactionRecords',
    component: Layout,
    meta: {
      perm: 'm:tr',
      title: '交易记录',
      icon: 'component'
    },
    children: [
      {
        path: 'transaction',
        name: 'transaction',
        component: _import('transactionRecords/transaction/index'),
        meta: {
          perm: 'm:tr:transaction',
          title: '交易明细查询',
          icon: 'documentation',
          noCache: true
        }
      },
      {
        path: 'recharge',
        name: 'recharge',
        component: _import('transactionRecords/recharge/index'),
        meta: {
          perm: 'm:tr:recharge',
          title: '消费查询',
          icon: 'documentation',
          noCache: true
        }
      },
      {
        path: 'refund',
        name: 'refund',
        component: _import('transactionRecords/refund/index'),
        meta: {
          perm: 'm:tr:refund',
          title: '退款查询',
          icon: 'documentation',
          noCache: true
        }
      },
      {
        path: 'impactIs',
        name: 'impactIs',
        component: _import('transactionRecords/impactIs/index'),
        meta: {
          perm: 'm:tr:impactIs',
          title: '冲正查询',
          icon: 'documentation',
          noCache: true
        }
      },
      {
        path: 'abnormal',
        name: 'abnormal',
        component: _import('transactionRecords/abnormal/index'),
        meta: {
          perm: 'm:tr:abnormal',
          title: '异常查询',
          icon: 'documentation',
          noCache: true
        }
      }
    ]
  },
  {
    // reconciliations 财务对账
    path: '/reconciliations',
    component: Layout,
    meta: {
      perm: 'm:rec',
      title: '财务对账',
      icon: 'component'
    },
    children: [
      {
        path: 'manualresult',
        name: 'manualresult',
        component: _import('reconciliations/manualresult/index'),
        meta: {
          perm: 'm:rec:manualresult',
          title: '手动对帐',
          icon: 'documentation',
          noCache: true
        }
      },
      {
        path: 'result',
        name: 'result',
        component: _import('reconciliations/result/index'),
        meta: {
          perm: 'm:rec:result',
          title: '对帐结果',
          icon: 'documentation',
          noCache: true
        }
      },
      {
        path: 'detailed',
        name: 'detailed',
        component: _import('reconciliations/detailed/index'),
        meta: {
          perm: 'm:rec:detailed',
          title: '对帐明细',
          icon: 'documentation',
          noCache: true
        }
      },
      {
        path: 'abnormal_detailed',
        name: 'abnormal_detailed',
        component: _import('reconciliations/abnormaldetailed/index'),
        meta: {
          perm: 'm:rec:abnormaldetailed',
          title: '异常明细',
          icon: 'documentation',
          noCache: true
        }
      }
    ]
  },
  {
    path: '/statistical_analysis',
    name: 'statistical_analysis',
    component: Layout,
    meta: {
      perm: 'm:sa',
      title: '统计分析',
      icon: 'documentation',
      noCache: true
    },
    children: [
      {
        path: 'all_summary',
        name: 'all_summary',
        component: _import('statisticalanalysis/allsummary/index'),
        meta: {
          perm: 'm:sa:all_summary',
          title: '所有汇总',
          icon: 'table',
          noCache: true
        }
      },
      {
        path: 'apply_summary',
        name: 'apply_summary',
        component: _import('statisticalanalysis/applysummary/index'),
        meta: {
          perm: 'm:sa:apply_summary',
          title: '应用汇总',
          icon: 'table',
          noCache: true
        }
      },
      {
        path: 'pay_summary',
        name: 'pay_summary',
        component: _import('statisticalanalysis/paysummary/index'),
        meta: {
          perm: 'm:sa:pay_summary',
          title: '支付渠道汇总',
          icon: 'table',
          noCache: true
        }
      },
      {
        path: 'detailed_summary',
        name: 'detailed_summary',
        component: _import('statisticalanalysis/detailedsummary/index'),
        meta: {
          perm: 'm:sa:detailed_summary',
          title: '明细汇总',
          icon: 'table',
          noCache: true
        }
      }
    ]
  },
  {
    path: '/order_manage',
    name: 'order_manage',
    component: Layout,
    meta: {
      perm: 'm:om',
      title: '订单管理',
      icon: 'documentation',
      noCache: true
    },
    children: [
      {
        path: 'all_order',
        name: 'all_order',
        component: _import('ordermanage/allorder/index'),
        meta: {
          perm: 'm:om:all_order',
          title: '所有订单',
          icon: 'table',
          noCache: true
        }
      },
      {
        path: 'abnormal_order',
        name: 'abnormal_order',
        component: _import('ordermanage/abnormalorder/index'),
        meta: {
          perm: 'm:om:abnormal_order',
          title: '异常订单',
          icon: 'table',
          noCache: true
        }
      },
      {
        path: 'unilateral_treat',
        name: 'unilateral_treat',
        component: _import('ordermanage/unilateraltreat/index'),
        meta: {
          perm: 'm:om:unilateral_treat',
          title: '单边处理',
          icon: 'table',
          noCache: true
        }
      }
    ]
  },
  // {
  //   path: '/menu4',
  //   name: 'menu4',
  //   component: Layout,
  //   // redirect: '/menu4/menu4_1/a',
  //   meta: {
  //     perm: 'm:menu4',
  //     title: '菜单4',
  //     icon: 'example'
  //   },
  //   children: [
  //     {
  //       path: '/menu4/menu4_1',
  //       name: 'menu4_1',
  //       component: _import('menu/menu4_1/index'),
  //       // redirect: '/menu4/menu4_1/a',
  //       meta: {
  //         perm: 'm:menu4:1',
  //         title: '菜单4-1',
  //         icon: 'table'
  //       },
  //       children: [
  //         {
  //           path: 'a',
  //           name: 'menu4_1_a',
  //           component: _import('menu/menu4_1/a'),
  //           meta: { perm: 'm:menu4:1:a', title: '菜单4-1-a' }
  //         },
  //         {
  //           path: 'b',
  //           name: 'menu4_1_b',
  //           component: _import('menu/menu4_1/b'),
  //           meta: { perm: 'm:menu4:1:b', title: '菜单4-1-b' }
  //         },
  //         {
  //           path: 'c',
  //           name: 'menu4_1_c',
  //           component: _import('menu/menu4_1/c'),
  //           meta: { perm: 'm:menu4:1:c', title: '菜单4-1-c' }
  //         }
  //       ]
  //     },
  //     {
  //       path: 'menu4/menu4_2',
  //       name: 'menu4_2',
  //       icon: 'tab',
  //       component: _import('menu/menu4_2/index'),
  //       meta: { perm: 'm:menu4:2', title: '菜单4-2' }
  //     }
  //   ]
  // },
  {
    path: '/system',
    component: Layout,
    meta: {
      perm: 'm:sys',
      title: '系统',
      icon: 'component'
    },
    children: [
      {
        path: 'org_manage',
        name: 'org_manage',
        component: _import('_system/org/index'),
        meta: {
          perm: 'm:sys:org',
          title: '机构管理',
          icon: 'documentation',
          noCache: true
        }
      },
      {
        path: 'user_manage',
        name: 'user_manage',
        component: _import('_system/user/index'),
        meta: {
          perm: 'm:sys:user',
          title: '用户管理',
          icon: 'documentation',
          noCache: true
        }
      },
      {
        path: 'role_manage',
        name: 'role_manage',
        component: _import('_system/role/index'),
        meta: {
          perm: 'm:sys:role',
          title: '角色管理',
          icon: 'documentation',
          noCache: true
        }
      },
      {
        hidden: true,
        path: 'role_manage/:roleId/assign_perm',
        name: 'role_manage_assign_perm',
        component: _import('_system/role/assign_perm'),
        meta: {
          hiddenTag: true,
          title: '角色授权'
        }
      },
      {
        path: 'perm_manage',
        name: 'perm_manage',
        component: _import('_system/perm/index'),
        meta: {
          perm: 'm:sys:perm',
          title: '权限管理',
          icon: 'documentation',
          noCache: true
        }
      },
      {
        path: 'apply_channel',
        name: 'apply_channel',
        component: _import('_system/applychannel/index'),
        meta: {
          perm: 'm:sys:applychannel',
          title: '应用渠道',
          icon: 'documentation',
          noCache: true
        }
      },
      {
        path: 'payment_mode',
        name: 'payment_mode',
        component: _import('_system/paymentmode/index'),
        meta: {
          perm: 'm:sys:paymentmode',
          title: '支付渠道',
          icon: 'documentation',
          noCache: true
        }
      },
      {
        hidden: true,
        path: 'payment_mode/:modeId/config',
        name: 'payment_mode_config',
        component: _import('_system/paymentmode/config'),
        meta: {
          hiddenTag: true,
          title: '参数配置'
        }
      }
    ]
  },
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]
